﻿using System;
using DZLib.ExtendFramework.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DZLib.ExtendFramework.UnitTests.Generic.ExtendIEnumerableTest
{
    [TestClass]
    public class IndexOfTest
    {
        [TestMethod]
        public void IndexOfNormTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var actualIndex = testCase.IndexOf(8);
            Assert.AreEqual(7, actualIndex);
        }

        [TestMethod]
        public void IndexOfMissTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var actualIndex = testCase.IndexOf(255);
            Assert.AreEqual(-1, actualIndex);
        }

        [TestMethod]
        public void IndexOfDuplicatedTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 8, 7 };
            var actualIndex = testCase.IndexOf(7);
            Assert.AreEqual(6, actualIndex);
        }

        [TestMethod]
        public void IndexOfEmptySrcTest()
        {
            var testCase = new int[] { };
            var actualIndex = testCase.IndexOf(100);
            Assert.AreEqual(-1, actualIndex);
        }

        [TestMethod]
        public void IndexOfOffsetNormTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var actualIndex = testCase.IndexOf(8, 5);
            Assert.AreEqual(7, actualIndex);
        }

        [TestMethod]
        public void IndexOfOffsetMissTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var actualIndex = testCase.IndexOf(255);
            Assert.AreEqual(-1, actualIndex);
        }

        [TestMethod]
        public void IndexOfOffsetMissOffTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var actualIndex = testCase.IndexOf(5, 8);
            Assert.AreEqual(-1, actualIndex);
        }

        [TestMethod]
        public void IndexOfOffsetDuplicatedNormTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 8, 7 };
            var actualIndex = testCase.IndexOf(7, 3);
            Assert.AreEqual(6, actualIndex);
        }

        [TestMethod]
        public void IndexOfOffsetDuplicatedOffTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 8, 7 };
            var actualIndex = testCase.IndexOf(7, 9);
            Assert.AreEqual(12, actualIndex);
        }

        [TestMethod]
        public void IndexOfOffsetEmptySrcTest()
        {
            var testCase = new int[] { };
            var actualIndex = testCase.IndexOf(100, 15);
            Assert.AreEqual(-1, actualIndex);
        }

        [TestMethod]
        public void IndexOfSetTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var targetSet = new int[] { 6, 7, 8 };
            var actualIndex = testCase.IndexOf(targetSet);
            Assert.AreEqual(5, actualIndex);
        }

        [TestMethod]
        public void IndexOfSetMissTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var targetSet = new int[] { 6, 8 };
            var actualIndex = testCase.IndexOf(targetSet);
            Assert.AreEqual(-1, actualIndex);
        }

        [TestMethod]
        public void IndexOfSetDuplicatedTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 8, 6, 8, 0 };
            var targetSet = new int[] { 6, 8 };
            var actualIndex = testCase.IndexOf(targetSet);
            Assert.AreEqual(5, actualIndex);
        }

        [TestMethod]
        public void IndexOfSetEmptyTargetTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 8, 6, 8, 0 };
            var targetSet = new int[] { };
            try
            {
                var actualIndex = testCase.IndexOf(targetSet);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
            }
        }

        [TestMethod]
        public void IndexOfSetEmptySrcTest()
        {
            var testCase = new int[] { };
            var targetSet = new int[] { 255, 169 };
            var actualIndex = testCase.IndexOf(targetSet);
            Assert.AreEqual(-1, actualIndex);
        }

        [TestMethod]
        public void IndexOfMinTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var actualIndex = testCase.IndexOfMin();
            Assert.AreEqual(9, actualIndex);
        }

        [TestMethod]
        public void IndexOfMaxTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            var actualIndex = testCase.IndexOfMax();
            Assert.AreEqual(8, actualIndex);
        }
    }
}
